package cn.chencq.moudle.sys.service.impl;

import java.util.List;
import java.util.Map;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.chencq.moudle.sys.dao.BaseDao;
import cn.chencq.moudle.sys.service.BaseService;
import cn.chencq.page.PageBean;
import cn.chencq.page.PageParam;

@SuppressWarnings({"rawtypes","unchecked"})
public abstract class BaseServiceImpl<T> implements BaseService<T> {

	protected abstract BaseDao getBaseDao();

	@Override
	public PageBean<T> listPage(PageParam pageParam) {
		Page page = PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
		List<T> recordList = getBaseDao().queryList(pageParam.getParams());
		return new PageBean<>(page, recordList);
	}

	@Override
	public void save(T t) {
		getBaseDao().save(t);
	}

	@Override
	public void batchSave(List<T> list) {
		getBaseDao().batchSave(list);
	}

	@Override
	public int updateByPrimaryKey(T t) {
		return getBaseDao().updateByPrimaryKey(t);
	}

	@Override
	public int deleteByPrimaryKey(Object id) {
		return getBaseDao().deleteByPrimaryKey(id);
	}

	@Override
	public int batchDeleteByPks(List<?> list) {
		return getBaseDao().batchDelete(list);
	}

	@Override
	public T selectByPrimaryKey(Object id) {
		return (T) getBaseDao().selectByPrimaryKey(id);
	}

	@Override
	public List<T> queryList(Map<String, Object> params) {
		return getBaseDao().queryList(params);
	}

}
